<template>
    <el-form :model="form"
             label-width="180px"
             @submit.prevent="onSubmit"
             ref="agentForm"
             style="margin:20px;width:60%;min-width:600px;">

        <el-form-item label="类别名称" required>
            <el-input v-model="form.name" auto-complete="off"></el-input>
        </el-form-item>

        <el-form-item label="排序">
            <el-input v-model="form.sort" auto-complete="off" placeholder="输入数字，越小越向前"></el-input>
        </el-form-item>

        <el-button type="primary"
                   @click.native.prevent="onSubmit">
            提交
        </el-button>
        <el-button @click.native.prevent="$router.go(-1)">返回</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    import {helpTypeEdit, getHelpTypeInfo} from '../../api/content';
    import UE from '../common/Ue.vue';

    export default {
        components: {
            UE
        },
        data() {
            return {
                loading: false,
                form: {
                    id: "",
                    name: "",
                    sort: "99",
                }
            }
        },
        created() {
            this.form.id = this.$route.params.id;
            if (this.form.id) {
                this.getHelpTypeInfo()
            }
        },
        methods: {
            onSubmit() {
                console.log(2)
                this.loading = true;
                helpTypeEdit(this.form).then((res) => {
                    this.loading = false;
                    this.ezNotifyAxiosThen(res);
                    if (res.status > 0) {
                        this.$router.push({path: '/content/helpTypes'});
                    }
                }).catch(error => this.ezNotifyAxiosCatch(error))
            },
            getHelpTypeInfo() {
                getHelpTypeInfo(this.form).then((res) => {
                    if (res.status == 1) {
                        this.form = res.data
                    }
                })
            }
        },
        computed: {

        }
    }
</script>

<style scoped>

</style>